
'use strict';

/**
	Part of Zombie Navigator
	Copyright © 2015  Zombie Navigator Developers
	
	@file
	@module
	@license AGPL-3.0+
*/


/* Used modules */
const _modConsole = require('../platform/console');
const _modNotification = require('../platform/notification');


/**
	Handle an error from a Zombie script
	@public
*/
const print = function (... errors) {
	const modConsole = _modConsole;
	const modNotification = _modNotification;
	
	const zConsole = modConsole.getConsole();
	
	for (let e of errors) {
		zConsole.error('' + e);
		
		try {
			modNotification.showNotification('Script failed: ' + e);
		} catch (e2) {
			// ignored
		}
		
		if ('stack' in e) {
			let stack = e.stack + '';
			stack = stack.split("\n").slice(0, 10).join("\n\t");
			zConsole.error('Stack: \n\t' + stack);
		}
	}
};


/* Exports */
exports.print = print;


// vim: ts=4 noet ai

